package com.foreknow.eldclient.dao;

import com.foreknow.eldclient.po.Food;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface FoodMapper {
    /**
     * 通过商家ID查询出该商家所有食品信息
     * @param businessId
     * @return
     * @throws Exception
     */
    @Select("select * from food where businessId=#{businessId} order by foodId")
    public List<Food> listFoodByBusinessId(Integer businessId) throws Exception;


    @Select("select * from food where foodName like concat('%',#{foodName},'%')")
    List<Food> listFoodByFoodName(String foodName) throws Exception;

    @Insert("insert into food(foodName,foodExplain,foodImg,foodPrice,businessId) values(#{foodName},#{foodExplain},#{foodImg},#{foodPrice},#{businessId})")
    int addFoodByBId(Food food);

    @Delete("delete from food where foodId =#{foodId}")
    int delFood(String foodId);

    @Update("update food set foodName=#{foodName},foodImg=#{foodImg},foodExplain=#{foodExplain},foodPrice=#{foodPrice} where foodId=#{foodId}")
    int updateFoodById(Food food);


    @Select("select * from food where foodId =#{foodId}")
    Food listFoodById(int foodId);

    @Select("select ifnull(foodSales,0) from food where foodId=#{foodId}")
    int getFoodSalesByFId(int foodId);

    @Update("update food set foodSales=#{foodSales} where foodId=#{foodId}")
    int updateFoodSales(Food food);

    @Select("select * from food order by foodSales desc limit 5")
    List<Food> listTop5Food();

    @Select("select * from food where foodName like concat('%',#{keyword},'%') and businessId=#{businessId}")
    List<Food> listFoodBykeyword(@Param("keyword") String keyword, @Param("businessId") int businessId) throws Exception;
}

